package br.com.caelum.vraptor.controller;

import java.util.List;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.components.AdministradorWeb;
import br.com.caelum.vraptor.components.UsuarioWeb;
import br.com.caelum.vraptor.dao.AdministradorDAO;
import br.com.caelum.vraptor.dao.GenericDAO;
import br.com.caelum.vraptor.dao.UsuarioDAO;
import br.com.caelum.vraptor.entidades.Administrador;
import br.com.caelum.vraptor.entidades.Usuario;

@Controller
public class AdministradorController {
	
	@Inject
	private Result result;
	
	@Inject
	private GenericDAO<Administrador> dao;
	@Inject
	private AdministradorDAO administradorDAO;
	@Inject
	private AdministradorWeb administradorWeb;
	
	
	public void add(){
		
	}
	
	
	public List<Administrador> list(){
		
		return dao.find();
		
	}
	
	
	public void save(Administrador administrador){
		
		dao.save(administrador);
		
		result.redirectTo(this).list();
	}
	
	public Administrador edit(Integer id){
		return dao.find(id);
	}
	
	public void delete(int id){
		Administrador perfil = new Administrador();
		perfil.setId(id);
		dao.delete(perfil);
		result.redirectTo(this).list();
	}
	   public void login(){}
	   
	    public void logout(){
         administradorWeb.logout();
    		result.redirectTo(this).login();
    	}
        
        public void logar(String login, String senha){
            Administrador Adm = administradorDAO.find(login, senha);
           administradorWeb.login(Adm);
            if(administradorWeb.isLogado()){
                    result.redirectTo(PratoController.class).list();
            }
            else{
                    result.redirectTo(IndexController.class);
                    }}
	 
	
}
